package datasv.courseProduce_datasv;

import po.CourseBasicPO;
import resultmessage.CourseProduceRM;
import data.datafactory.DatabaseOperator;
import datasv.collegeQuery_datasv.CollegeQueryDatasvController;

public class DeleteCourseBasic {
	public static void main(String[] args) {
		System.out.println(new DeleteCourseBasic()
				.deleteCourseBasic("00101130020"));
	}

	public CourseProduceRM deleteCourseBasic(String courseID) {
		return deleteInSql(courseID);
	}

	private CourseProduceRM deleteInSql(String courseID) {
		String collegeID = courseID.substring(0, 3);
		DatabaseOperator op = new DatabaseOperator("college" + collegeID);
		if (!op.ifDatabaseExist() || !op.ifIDExist("course_list", courseID)) {
			return CourseProduceRM.COURSE_ID_NOT_EXSIT;
		}
		int num = AddCourseBasic.columnNum;
		String courseName=op.getOneInform(courseID,"course_list", "name");
		for (int i = 1; i < num; i++) {
			if (!AddCourseBasic.columnName[i].equals("name")) {
				if (!op.deleteOneInfo("course_list", courseID,
						AddCourseBasic.columnName[i])) {
					return CourseProduceRM.COURSEBASIC_NOT_EXSIT;
				}
			}
			// System.out.println(AddCourseBasic.columnName[i]);
		}
		new AddCourseBasic().addCourseBasic(new CourseBasicPO(courseID, courseName, -1, -1, -1, -1, "null","null" , "null", -1));
		op.deleteOneInfo("course_list", courseID, "campus");
		op.deleteOneInfo("course_list", courseID, "department");
		
		return CourseProduceRM.SUCCESS;
	}
}
